package com.abc.cloud.service.impl;

import com.abc.cloud.entity.UserEntity;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.abc.cloud.common.utils.PageUtil;
import com.abc.cloud.common.utils.Query;

import com.abc.cloud.dao.UserNoticeDao;
import com.abc.cloud.entity.UserNoticeEntity;
import com.abc.cloud.service.UserNoticeService;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Service("userNoticeService")
public class UserNoticeServiceImpl extends ServiceImpl<UserNoticeDao, UserNoticeEntity> implements UserNoticeService {

    @Resource
    private SqlSessionFactory sqlSessionFactory;

    @Override
    public PageUtil queryPage(Map<String, Object> params) {
        IPage<UserNoticeEntity> page = this.page(
                new Query<UserNoticeEntity>().getPage(params),
                new QueryWrapper<UserNoticeEntity>()
        );

        return new PageUtil(page);
    }

    @Override
    public void saveNotice(Long targetId, Long id, int i) {
        UserNoticeEntity userNoticeEntity = new UserNoticeEntity();
        userNoticeEntity.setIsRead(i);
        userNoticeEntity.setNoticeId(id);
        userNoticeEntity.setUserId(targetId);
        this.baseMapper.insert(userNoticeEntity);
    }

    @Override
    public void saveAllUserNotice(List<UserEntity> userEntityList, Long id, int i) {
        this.baseMapper.saveAllUserNotice(userEntityList, id, i);
    }
}